package com.nbjtjc.safe.wps.controller;

import com.alibaba.fastjson.JSON;
import com.nbjtjc.safe.api.sys.SysUserController;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.wps.dto.FileReqDTO;
import com.nbjtjc.safe.wps.service.WpsFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("v1/3rd/file")
public class FileCallBackController {

    private static Logger logger = LoggerFactory.getLogger(FileCallBackController.class);

    @Autowired
    private WpsFileService wpsFileService;

    @GetMapping("info")
    public Map<String, Object> getFileInfo(String _w_userid, String _w_fileid) {
        logger.info("获取文件元数据userId:{},file:{}", _w_userid, _w_fileid);
        logger.info("获取文件元数据"+ _w_userid+"-"+ _w_fileid);
        System.out.println("获取文件元数据"+_w_userid+":"+_w_fileid);
        return wpsFileService.getFileInfo(_w_userid, _w_fileid);
    }

    @PostMapping("save")
    public Map<String,Object> fileSave(@RequestBody MultipartFile file, String _w_userid) {
        logger.info("保存文件1"+ _w_userid);
        System.out.println("保存文件2"+_w_userid);
        Map<String,Object> result= wpsFileService.fileSave(file,_w_userid);
        return result;
    }

    @PutMapping("/rename")
    public Result fileRename(@RequestBody FileReqDTO req,String _w_userid){
        logger.info("文件重命名param:{},userId:{}", JSON.toJSONString(req),_w_userid);
        wpsFileService.renameFile(req.getName(),_w_userid);
        return Result.res();
    }

    @PostMapping("/history")
    public Map<String ,Object> fileHistory(@RequestBody FileReqDTO req){
        logger.info("获取所有历史版本文件信息param:{}", JSON.toJSON(req));
        System.out.println("获取文件元数据"+req.toString());
        return  wpsFileService.fileHistory(req);
    }

}
